{% extends "base.html" %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}

{% block title %}万屏时代报价工具--新增品牌型号{% endblock %}

{% block panel_heading %}万屏时代报价工具--新增品牌型号{% endblock %}

{% block panel_body %}
    <form id="add-spec-form"
          action="{{ url_for('product_bp.add_brand_model') }}" method="post"
          class="form" role="form">

        {{ my_wtf_macros.form_field(form.product_type_id, div_col=8, label_col=3, field_col=9) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        {{ my_wtf_macros.form_field(form.brand_id, div_col=8, label_col=3, field_col=9) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        {{ my_wtf_macros.form_field(form.model_name, div_col=8, label_col=3, field_col=9) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        {{ my_wtf_macros.form_field(form.weight, div_col=8, label_col=3, field_col=9) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <div class="pull-right">
            <button type="submit" class="btn btn-success"
                    id="add-demand-btn">
                新增
            </button>
        </div>

    </form>

{% endblock %}


{% block scripts %}
    {{ super() }}
    <script>
        function get_brands_by_type() {
            var product_type_id = $('#product_type_id').val();
            $.ajax({
                url: "{{ url_for('product_bp.ajax_brand_choices')}}",
                data: JSON.stringify({
                    'product_type_id': product_type_id
                }),
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                cache: true
            }).done(function (data) {
                $("#brand_id").empty();
                for (var i = 0; i < data.length; i++) {
                    var id = data[i][0];
                    var name = data[i][1];
                    $("#brand_id").append(
                        "<option value='" + id + "'>" + name + "</option>"
                    );
                }

            }).fail(function () {
                $(obj).data('content', '服务器错误');
                $(obj).popover('show');
            });
        }
        $(document).ready(function () {
            $("#product_type_id").change(function () {
                get_brands_by_type();
            });
            var product_type_id = $("#product_type_id").val();
            if (product_type_id != 0) {
                get_brands_by_type();
            }
        })
    </script>


{% endblock %}
